TOP=$(shell pwd)

SM2_SRC_DIR=$(TOP)/src/sm2
SM3_SRC_DIR=$(TOP)/src/sm3
SM4_SRC_DIR=$(TOP)/src/sm4

test_target=a.out
static_lib_target=libsw-engine.a
share_lib_target=libsw-engine.so

# sm2,3,4
LIB_SRC = $(wildcard $(SM2_SRC_DIR)/*.c)
LIB_SRC += $(wildcard $(SM3_SRC_DIR)/*.c)
LIB_SRC += $(wildcard $(SM4_SRC_DIR)/*.c)
LIB_OBJ := $(patsubst %.c,%.o,$(LIB_SRC))

# test
TEST_SRC := $(wildcard $(TOP)/test/*.c)
TEST_JOB := $(patsubst %.c,%.o,$(TEST_SRC))

CC = gcc
CFLAGE = -Wall -g
INCLUDE_FLAGE = -I$(TOP)/inc/sm2/ -I$(TOP)/inc/sm3/ -I$(TOP)/inc/sm4/

all:$(test_target) $(static_lib_target) $(share_lib_target)

$(share_lib_target): $(LIB_OBJ)
	@$(CC) -shared -fPIC $^ -o $@

$(static_lib_target): $(LIB_OBJ)
	@ar rcs -o $@ $^ 

$(test_target): $(LIB_OBJ) $(TEST_JOB)
	@$(CC) $^ -o $@

%.o : %.c
	@$(CC) $(CFLAGE) $(INCLUDE_FLAGE) -c -fPIC $< -o $@

clean:
	@rm $(test_target) $(TEST_JOB) $(LIB_OBJ) $(static_lib_target) $(share_lib_target)
